package com.ccb.sc.common.bind;

import com.ccb.sc.common.constant.CommonConstant;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;

/**
 * @author ken
 * @version 1.0
 * @date 2020-09-14
 */
public class BaseController {

    /**
     * 添加日志
     *
     * @param operateType 操作类型
     */
    protected void addLog(String operateType) {
        if (operateType != null) {
            RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes();
            requestAttributes.setAttribute(CommonConstant.LOG_OPERATE_TYPE_REQUEST_KEY, operateType, RequestAttributes.SCOPE_REQUEST);
        }
    }

    /**
     * 添加日志
     *
     * @param operateType 日志类型
     * @param content     内容
     */
    protected void addLog(String operateType, String content) {
        this.addLog(operateType);
        if (content != null) {
            RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes();
            requestAttributes.setAttribute(CommonConstant.LOG_CONTENT_REQUEST_KEY, content, RequestAttributes.SCOPE_REQUEST);
        }
    }
}
